<template>
	<view class="container">
		<!-- 收藏分类 -->
		<view class="card mb-20">
			<scroll-view scroll-x class="scroll-x">
				<view class="flex">
					<view class="category-item" :class="{active: activeCategory === index}" v-for="(item, index) in categoryList" :key="index" @click="switchCategory(index)">
						{{ item }}
					</view>
				</view>
			</scroll-view>
		</view>
		
		<!-- 收藏列表 -->
		<view class="collection-list">
			<view class="card mb-20" v-for="(item, index) in collectionList" :key="index">
				<view class="flex" @click="goToDetail(item)">
					<image :src="item.image" mode="aspectFill" style="width: 150rpx; height: 150rpx; border-radius: 10rpx;"></image>
					<view style="flex: 1; margin-left: 20rpx;">
						<text class="block" style="font-weight: bold;">{{ item.title }}</text>
						<text class="block text-gray mt-10">{{ item.desc }}</text>
						<view class="flex justify-between mt-10">
							<text class="text-red">¥{{ item.price }}</text>
							<text class="text-gray">{{ item.sales }}人已购买</text>
						</view>
					</view>
				</view>
				<view class="flex justify-end mt-20">
					<text class="button-line" style="padding: 10rpx 20rpx; font-size: 24rpx;" @click.stop="cancelCollection(item)">取消收藏</text>
				</view>
			</view>
		</view>
		
		<!-- 空状态 -->
		<view class="empty-container text-center" v-if="collectionList.length === 0">
			<text class="iconfont icon-collect" style="font-size: 100rpx; color: #ccc;"></text>
			<text class="block mt-20">暂无收藏</text>
			<text class="block text-gray mt-10">快去收藏喜欢的内容吧</text>
			<view class="button mt-20" @click="goToHome">去首页逛逛</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				activeCategory: 0,
				categoryList: ['全部', '门票', '酒店', '资讯', '玩乐'],
				collectionList: [
					{
						id: 1,
						title: '故宫博物院',
						desc: '明清两代的皇家宫殿，世界上现存规模最大、保存最完整的木质结构古建筑之一',
						price: 60,
						sales: 1280,
						image: '/static/gugong.jpg',
						type: 'ticket'
					},
					{
						id: 2,
						title: '北京环球影城',
						desc: '全球首个"功夫熊猫盖世之地"主题景区，沉浸式体验中国武侠文化',
						price: 528,
						sales: 3200,
						image: '/static/huanqiu.jpg',
						type: 'ticket'
					},
					{
						id: 3,
						title: '北京王府井大酒店',
						desc: '地处繁华的王府井商业区，地理位置优越',
						price: 680,
						sales: 960,
						image: '/static/hotel1.jpg',
						type: 'hotel'
					}
				]
			}
		},
		methods: {
			switchCategory(index) {
				this.activeCategory = index;
				// 实际开发中这里需要重新请求对应分类的收藏数据
			},
			goToDetail(item) {
				switch(item.type) {
					case 'ticket':
						uni.navigateTo({
							url: '/pages/ticket/detail?id=' + item.id
						})
						break;
					case 'hotel':
						uni.navigateTo({
							url: '/pages/hotel/detail?id=' + item.id
						})
						break;
				}
			},
			cancelCollection(item) {
				uni.showModal({
					title: '提示',
					content: '确定要取消收藏吗？',
					success: (res) => {
						if (res.confirm) {
							// 实际开发中这里需要调用取消收藏接口
							uni.showToast({
								title: '已取消收藏',
								icon: 'success'
							})
						}
					}
				})
			},
			goToHome() {
				uni.switchTab({
					url: '/pages/index/index'
				})
			}
		}
	}
</script>

<style>
	.scroll-x {
		white-space: nowrap;
		width: 100%;
	}
	
	.category-item {
		display: inline-block;
		padding: 15rpx 30rpx;
		margin-right: 20rpx;
		border-radius: 30rpx;
		background: #f5f5f5;
	}
	
	.category-item.active {
		background: #4caf50;
		color: #fff;
	}
	
	.button-line {
		border: 1rpx solid #007AFF;
		color: #007AFF;
		border-radius: 10rpx;
		text-align: center;
	}
	
	.empty-container {
		padding-top: 200rpx;
	}
</style>
